package com.zhida.smartcontrol.pagemy;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.jay.tools.ui.CircleImageView;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.launch.bottom.BottomItemFragment;
import com.zhida.smartcontrol.launch.login.LoginFragment;
import com.zhida.smartcontrol.launch.login.bean.DepartsBean;
import com.zhida.smartcontrol.launch.login.bean.UserInfoBean;

import java.util.List;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.OnClick;

/**
 * author: tanjianpei
 * date: 2019/10/8 008 17:03
 * description: 我的
 */
public class PageMyFragment extends BottomItemFragment<PageMyContract.View, PageMyPresenter> implements PageMyContract.View {
    @BindView(R.id.iv_head)
    CircleImageView mIvHead;
    @BindViews({R.id.tv_name, R.id.tv_phone, R.id.tv_org, R.id.tv_department, R.id.tv_phone_num, R.id.tv_emil, R.id.tv_note})
    List<TextView> mTvList;

    @Override
    protected Object getLayout() {
        return R.layout.fragment_page_my;
    }

    @Override
    protected void initLazy(Bundle savedInstanceState) {
        mPresenter.fillInfo();
    }

    @Override
    public void showInfo(UserInfoBean userInfo, DepartsBean departBean) {
        Glide.with(getProxyActivity())
                .load(userInfo.getAvatar())
                .apply(new RequestOptions()
                        .error(R.drawable.ic_head)
                        .placeholder(R.drawable.ic_head))
                .into(mIvHead);

        mTvList.get(0).setText(userInfo.getRealname());
        mTvList.get(1).setText(userInfo.getUsername());
//        mTvList.get(2).setText(departBean.getDepartName());
//        mTvList.get(3).setText(departBean.getDepartName());
        mTvList.get(4).setText(userInfo.getPhone());
        mTvList.get(5).setText(userInfo.getEmail());
        mTvList.get(6).setText("");
    }

    @OnClick({R.id.btn_out})
    public void click(View v) {
        switch (v.getId()) {
            case R.id.btn_out:
                mPresenter.loginOut();
                break;
        }
    }

    @Override
    public void loginOutOk() {
        getParentDelegate().startWithPop(LoginFragment.newInstance());
    }


}
